package web

type ApiResponse[T any] struct {
	Data    T      `json:"data"`
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type ResponseOptions[T any] func(r ApiResponse[T])

func WithCode[T any](code int) ResponseOptions[T] {
	return func(r ApiResponse[T]) {
		r.Code = code
	}
}

func WithData[T any](data T) ResponseOptions[T] {
	return func(r ApiResponse[T]) {
		r.Data = data
	}
}

// func OkResponse(options ...ResponseOptions) ApiResponse{

// }
func OkResponse[T any](data T) ApiResponse[T] {
	return ApiResponse[T]{Data: data, Code: 200, Message: "SUCCESS"}
}

func ErrorResponse(code int) ApiResponse[any] {
	return ApiResponse[any]{Data: nil, Code: code, Message: "Fail"}
}
